import React, { useEffect, useState } from 'react'
import api from '@/api'
import {
    Space, Table, Tag, Image, Button, Drawer, message,
    Cascader,
    Checkbox,
    DatePicker,
    Form,
    Input,
    InputNumber,
    Radio,
    Select,
    Switch,
    TreeSelect,
    Upload,
    Pagination,
    Card
} from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { SearchOutlined, EditOutlined, CloseOutlined, PlusOutlined } from '@ant-design/icons';
export default function OrderHistory() {
    const [list, setList] = useState([])
    const [total, setTotal] = useState()
    const [send, setSend] = useState({
        pageSize: 2,
        currentPage: 1,
        way: 0

    })
    async function getList(params: any) {
        const res = await api.worker.getHistoryList(params)
        console.log('list', res.data);
        setList(res.data.data)
        setTotal(res.data.total)

    }
    useEffect(() => {
        getList(send)
    }, [])
    const columns: ColumnsType<any> = [
        {
            title: '订单编号',
            dataIndex: 'id',
            key: 'id'
        },
        {
            title: '服务名称',
            dataIndex: 'servegoodsname',
            key: 'servegoodsname'
        },
        {
            title: '开始时间',
            dataIndex: 'createdAt',
            key: 'createdAt'
        },
        {
            title: '结束时间',
            dataIndex: 'endtime',
            key: 'endtime'
        },

    ]
    function pageChange(args: any) {
        getList({ ...send, currentPage: args })
        setSend({ ...send, currentPage: args })
    }
    function handleChange(args: any) {
        console.log(args);
        getList({ ...send, currentPage: 1, way: Number(args) })
        setSend({ ...send, currentPage: 1, way: Number(args) })
    }
    return (
        <div>
            <Card>
                <Select
                    onChange={handleChange}
                    defaultValue="筛选"
                    style={{ width: 120 }}
                    options={[{ value: 0, label: '选择全部' }, { value: 1, label: '已完成历史订单' }, { value: 2, label: '未完成历史订单' }]}
                />
                <Table columns={columns} dataSource={list} pagination={false} />
                <Pagination total={total} current={send.currentPage} pageSize={send.pageSize} onChange={pageChange}></Pagination>
            </Card>
        </div>
    )
}
